<?php

require_once APPPATH . 'core/BaseDAO.php';

use models\M_cobrador;

class CobradorDAO extends BaseDAO {

    function __construct() {
        parent::__construct();
    }
	
    public function getCobradores(){
		
        try {

            $query = $this->em->createQuery('SELECT c FROM models\M_cobrador c');

            $cobradores = $query->getResult();

            return empty($cobradores) ? FALSE : $cobradores;
			
        } catch (Exception $e) {
            return FALSE;
        }
    }
    
    public function getCobradorBy($valor, $campo, $tipo) {

        try {

            $comparador = $tipo === 'string' ? 'like' : '=';

            $qb = $this->em->createQueryBuilder();
            $qb->add('select', 's')
                    ->add('from', 'models\M_datos_socio s')
                    ->add('where', 's.' . $campo . ' ' . $comparador . ' ?1')
                    ->setParameter(1, $valor);

            $persona = $qb->getQuery()->getResult();

            return empty($persona) ? FALSE : $persona[0];
        } catch (Exception $e) {

            return FALSE;
        }
    }
    
}